package com.www.applyword.adapter;

import android.content.Context;
import android.widget.Button;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.bean.LoginBean;
import com.www.applyword.bean.OrderItemBean;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;
import com.www.applyword.ui.home.EmployedActivity2;
import com.www.applyword.utils.ImageUtil;
import com.www.applyword.utils.Utils;

import java.util.HashMap;
import java.util.Map;

/**
 * author : huang
 * date   : 2019/10/21 0021 15:06
 * version: 1.0
 * @author Administrator
 */
public class HomeAdapter3 extends CommonRecyclerAdapter<OrderItemBean> {
    private EmployedActivity2 context;
    public HomeAdapter3(Context context) {
        super(context, R.layout.item_list_employed);
        this.context = (EmployedActivity2) context;
    }


    @Override
    public void onUpdate(BaseAdapterHelper helper, OrderItemBean item, int position) {
        helper.setText(R.id.tv_name,item.getOrderItem_UserName());
        helper.setText(R.id.tv_time,"报到时间:" + item.getOrderItem_CreateTime());
        ImageUtil.setImage(helper.getView(R.id.iv1), (String) item.getOrderItem_UserHeadImg());


        if (item.getOrderItem_State() == 2){
            helper.setText(R.id.sb1,"已到岗");
            helper.getView(R.id.sb1).setEnabled(false);
        }else {
            helper.setText(R.id.sb1,"到岗");
        }


        helper.getView(R.id.sb1).setOnClickListener(v -> {
            Map<String, Object> params = new HashMap<>();
           // params.put("OrderID",item.getOrderItem_OrderID());
            params.put("OrderItemsID",item.getOrderItem_ID());
            HttpClient.get(context, Constants.SIGNIN, params,new CallBack<LoginBean>() {
                @Override
                public void onSuccess(LoginBean result) {
                     Utils.showToastSafe("签到成功");
                     Button sb1 = (Button)helper.getView(R.id.sb1);
                     sb1.setText("已到岗");
                     sb1.setEnabled(false);
                     notifyDataSetChanged();
                }
            });
        });
    }
}

